﻿using System;
using System.Data.Entity;
using System.Linq;
using CodeContrib;

namespace CodeContribBlog.Data
{
	public static class CommeterExtensions
	{
		public static Commenter FindByKey(this IDbSet<Commenter> commenters, string commenterKey)
		{
			if (!commenterKey.IsGuid())
			{
				return null;
			}

			return FindByKey(commenters, Guid.Parse(commenterKey));
		}

		public static Commenter FindByKey(this IDbSet<Commenter> commenters, Guid? commenterKey)
		{
			if (commenterKey == null)
			{
				return null;
			}

			return FindByKey(commenters, commenterKey.Value);
		}

		public static Commenter FindByKey(this IDbSet<Commenter> commenters, Guid commenterKey)
		{
			return commenters.SingleOrDefault(c => c.Key == commenterKey);
		}
	}
}